package com.linkage.jz.bankruptcy.widget;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Display;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.linkage.jz.bankruptcy.R;

public class PublicLoginNoticeDialog extends Dialog {

	/**
	 * 上下文对象 *
	 */
	Activity context;

	private Button btn_save_notice,btn_chancel_notice;

	private LinearLayout ll_notice,ll_bt_z,ll_close;
	public TextView notice_title,tv_content;


	private View.OnClickListener mClickListener;

	/*
	1.标题  内容 确定 取消 关闭
	2.标题  确定 取消 关闭
	3.标题  确定 关闭
	4.标题  内容 关闭
		5.标题  内容 确定 关闭
	 */
	private int mType = -1;
	private String mTitle;
	private String mContent;
	private String mCanceltitle;
	private String mSavetitle;


	public PublicLoginNoticeDialog(Activity context) {
		super(context);
		this.context = context;
	}

	public PublicLoginNoticeDialog(Activity context, View.OnClickListener clickListener, int type,
                                   String title, String content, String canceltitle, String savetitle) {
		super(context);
		this.context = context;
		mType = type;
		mTitle = title;
		mContent  = content;
		mCanceltitle = canceltitle;
		mSavetitle = savetitle;
		this.mClickListener = clickListener;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 指定布局

		this.setContentView(R.layout.public_notice_dialog);

		/*
		1.标题  内容 确定 取消 关闭
		2.标题  确定 取消 关闭
		3.标题  确定 关闭
		4.标题  内容 关闭
		5.标题  内容 确定 关闭
		 */

		notice_title =  findViewById(R.id.notice_title);
		tv_content =  findViewById(R.id.tv_content);

		ll_notice =  findViewById(R.id.ll_notice);
		ll_bt_z =  findViewById(R.id.ll_bt_z);
		btn_chancel_notice =  findViewById(R.id.btn_chancel_notice);
		btn_save_notice =  findViewById(R.id.btn_save_notice);
		ll_close = findViewById(R.id.ll_close);

		btn_chancel_notice.setOnClickListener(mClickListener);
		btn_save_notice.setOnClickListener(mClickListener);
		ll_close.setOnClickListener(mClickListener);

		ll_close.setVisibility(View.INVISIBLE);
		notice_title.setText(mTitle);
		tv_content.setText(mContent);
		btn_chancel_notice.setText(mCanceltitle);
		btn_save_notice.setText(mSavetitle);

		/*
	1.标题  内容 确定 取消 关闭
	2.标题  确定 取消 关闭
	3.标题  确定 关闭
	4.标题  内容 关闭
		5.标题  内容 确定 关闭
	 */

		if(mType ==2)
		{
			ll_notice.setVisibility(View.GONE);
		}
		if(mType ==3)
		{
			ll_notice.setVisibility(View.GONE);
			btn_save_notice.setVisibility(View.GONE);
		}
		if(mType == 4)
		{
			btn_save_notice.setVisibility(View.GONE);
			ll_bt_z.setVisibility(View.GONE);
		}
		if(mType == 5)
		{
			btn_chancel_notice.setVisibility(View.GONE);
		}
		/*
		 * 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置, 可以直接调用getWindow(),表示获得这个Activity的Window
		 * 对象,这样这可以以同样的方式改变这个Activity的属性.
		 */
		Window dialogWindow = this.getWindow();

		WindowManager m = context.getWindowManager();
		Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
		WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
		// p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
		p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.8
		dialogWindow.setAttributes(p);

		// 根据id在布局中找到控件对象
//		btn_save_u = (Button) findViewById(R.id.btn_save_u);
//
//		btn_chancel_u = (Button)findViewById(R.id.btn_chancel_u);
//		// 为按钮绑定点击事件监听器
//		btn_save_u.setOnClickListener(mClickListener);
//		btn_chancel_u.setOnClickListener(mClickListener);

		this.setCancelable(false);
	}

	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		if(event.getKeyCode() == KeyEvent.KEYCODE_BACK ) {
			//do something.
			if(isShowing())
			{
				return  false;
			}else{
				return  true;
			}

		}else {
			return super.dispatchKeyEvent(event);
		}
	}

}


